require('./env_demo.js')
const crypto = require('crypto');
let deasync = require("deasync")
window._fmOpt = {
    partner: "popmart",
    appName: "popmart_web",
    token: "popmart_test-" + new Date().getTime() + "-" + Math.random().toString(16).substr(2),
    interfaceProtection: !0,
    timeout: 5e3,
    success: function (t) {
        window.blackbox = t;
        console.log("tt:::", t)
    }
};
require('./esign.js')

function fun1() {
    return new Promise((resolve) => {
        const checkInterval = setInterval(() => {
            if (typeof window !== 'undefined' && window._fmOpt && typeof window._fmOpt.sign === 'function') {
                clearInterval(checkInterval);
                resolve();
            }
        }, 100);
    });
}

const waitForSign = deasync((callback) => {
    fun1()
        .then(() => callback(null))
        .catch((error) => callback(error));
});

function p(str) {
    return crypto.createHash('md5').update(str).digest('hex');
}

waitForSign()

function get_xsign(t) {
    e = "nw3b089qrgw9m7b7i";
    // t = Number(Date.now().toString().slice(0, 10));
    n = "".concat(t, ",").concat(e);
    xsign = "".concat(p(n), ",").concat(t);
    return xsign;
}
// var params={};
// var time = Math.floor(new Date().getTime() / 1e3);

function get_s(t){
    a = {};
    let c = "".concat(JSON.stringify(a)).concat("W_ak^moHpMla").concat(t);
    console.log("c:::", c)
    return p(c)
}
console.log(p('{}W_ak^moHpMla1753424075'))
// console.log("sss:::",get_s(time));
function getSign(a, b) {
    let par = {path: a, body: JSON.stringify(b)}
    return window._fmOpt.sign(par)
}

// sign = window._fmOpt.sign
// sign = window._fmOpt.sign({ path: "/shop/v1/search", body: JSON.stringify({ "pageSize": 20, "page": 4, "strategy": "", "term": "LABUBU", "categoryIds": [], "brandIds": [] }) })
// console.log('sign:::', sign)